home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / web / noweb / src / shell / noweb.nw (.txt) < prev    next >
LaTeX Document  |  1995-02-24  |  2KB  |  64 lines

  1. \section{Generating all outputs from a {\tt noweb} file}
  2. The copyright applies both to the {\tt noweb} source and to the
  3. generated shell script.
  4. <<copyright notice>>=
  5. # Copyright 1991 by Norman Ramsey.  All rights reserved.
  6. # See file COPYRIGHT for more information.
  7. Here's the organization of the source:
  8. <<noweb>>=
  9. #!/bin/sh
  10. <<copyright notice>>
  11. LIB=|LIBDIR|
  12. markup=$LIB/markup mntopt=-L status=0 tex=1 output=1
  13. <<consume options, setting [[tex]], [[output]], [[mntopt]], and [[markup]]>>
  14. if [ $# -eq 0 ]; then <<complain of no args and exit>>; fi
  15. for source do
  16.   if [ -n "$output" ]; then 
  17.     PATH="$PATH:$LIB" $markup -t $source | $LIB/mnt -t8 "$mntopt" -all || status=1
  18.   if [ -n "$tex" ]; then
  19.     <<write {\TeX} output>> || status=1
  20. exit $status
  21. {\tt noweb} could be modified to follow two Knuth-like and {\tt nuweb}-like conventions:
  22. \begin{itemize}
  23. \item
  24. Treat multiple white space within chunk names as single blanks, and
  25. ignore leading and trailing whitespace.
  26. \item
  27. Permit chunk names to be abbreviated by writing an initial subsequence
  28. of the name followed by ``[[...]]''.
  29. \end{itemize}
  30. The modification is simple; just add these two programs to the
  31. pipeline.
  32. ([[disambiguate]] is an Icon program found in the [[icon]] directory
  33. of the [[noweb]] distribution.)
  34. <<compress multiple blanks in uses and defns>>=
  35. sed -e '/^@[ud][se][ef][ n]/s/[     ][     ]*/ /g' \
  36.     -e '/^@[ud][se][ef][ n]/s/ $//'
  37. <<disambiguate uses and defns ending in three dots>>=
  38. $LIB/disambiguate
  39. When writing {\TeX} output, I call [[$markup]] a second time to expand tabs.
  40. %% timings on nuweb
  41. % markup 0.4u 0.1s
  42. % noxref 3.9u 1.0s
  43. % nawk   6.5u 0.2s
  44. <<write {\TeX} output>>=
  45. texname=`echo $source | sed '/\./s/\.[^.]*$//'`
  46. texname="$texname.tex"
  47. PATH="$PATH:$LIB" $markup $source | $LIB/finduses -noquote | $LIB/noidx -delay | 
  48. nawk '{print}
  49. /^@defn [^ ]*$/ { print "@literal \\let\\nwnotused=\\nwoutput{}" }' |
  50. $LIB/totex -delay | cpif $texname
  51. <<consume options, setting [[tex]], [[output]], [[mntopt]], and [[markup]]>>=
  52. while [ $# -gt 0 ]; do
  53.   case $1 in
  54.     -to|-ot) tex= output= ; shift ;;
  55.     -t)  tex=             ; shift ;;
  56.     -o)  output=          ; shift ;;
  57.     -L*) mntopt="$1"      ; shift ;;
  58.     -markup) markup="$2"  ; shift; shift ;;
  59.     -*)  echo "Unrecognized option $1" 1>&2; exit 1 ;;
  60.     *) break ;;
  61.   esac
  62. <<complain of no args and exit>>=
  63. echo "Usage: $0 [-L[fmt] -t -o] file [...]" 1>&2; exit 1
  64.